//
//  EditTaskViewController.m
//  OAProject
//
//  Created by yhj on 2017/3/30.
//  Copyright © 2017年 cdnunion. All rights reserved.
//  编辑任务主界面

#import "EditTaskViewController.h"
#import "CommonTableViewCell.h"
#import "MemberTableViewCell.h"
#import "ProjectListViewController.h"
#import "TaskProcessViewController.h"
#import "RemarkTableViewCell.h"
#import "TaskSortViewController.h"
#import "LQPopUpView.h"
#import "FileViewController.h"
#import "TaskListViewController.h"
#import "MCAWSS3Client.h"
#import "NSString+SizeFile.h"


static NSString *RemarkTableViewCellIdentifier=@"RemarkTableViewCellIdentifier";
static NSString *MemberTableViewCellIdentifier=@"MemberTableViewCellIdentifier";
static NSString *CommonTableViewCellIdentifier=@"CommonTableViewCellIdentifier";
@interface EditTaskViewController ()<UITableViewDelegate,UITableViewDataSource,RemarkTableViewCellDelegate,CuiPickViewDelegate,UITextViewDelegate,ProjectListViewControllerDelegate,TaskSortViewControllerDelegate,UITextFieldDelegate>

@property(nonatomic,strong)UITableView *addTaskTableView;
@property(nonatomic,strong)UIView *taskInfoView;
@property(nonatomic,strong)CuiPickerView *pickerView;

// 任务名称
@property(nonatomic,strong)UITextField *nameTF;

// 任务目标
@property(nonatomic,strong)UITextView *taskGoalTV;

// 执行方法
@property(nonatomic,strong)UITextView *taskMethodTV;


// 项目名称
@property(nonatomic,strong)NSString *projectName;
@property(nonatomic,strong)NSString *projectID;

// 分类名称
@property(nonatomic,strong)NSString *sortName;
@property(nonatomic,strong)NSMutableArray *sortIDsArr;

// 开始时间
@property(nonatomic,strong)NSString *startTimeStr;

// 优先级
@property(nonatomic,strong)NSString *priorityStr;
@property(nonatomic,strong)NSString *priorityID;

// 备注
@property(nonatomic,strong)NSString *remarkStr;


@property(nonatomic,assign)BOOL isChangeProject;

@property(nonatomic,assign)BOOL isChangeSort;

@property(nonatomic,assign)BOOL isChangeTime;

@property(nonatomic,assign)BOOL isChangePriority;

@property(nonatomic,assign)BOOL isChangeFile;


@property(nonatomic,strong)NSMutableDictionary *dicKey;


@end

@implementation EditTaskViewController

-(void)GetTextViewHeightByInputRemarkStr:(NSString *)remarkStr textViewHeight:(CGFloat)textViewHeight cell:(RemarkTableViewCell *)cell
{
    self.remarkStr=remarkStr;
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title=@"修改任务";

    _isChangeProject=NO;

    _isChangeSort=NO;

    _isChangeTime=NO;

    _isChangePriority=NO;

    _isChangeFile=NO;

    _sortIDsArr=[NSMutableArray array];

    self.dicKey=[NSMutableDictionary dictionary];

    [self.view addSubview:self.addTaskTableView];

    [self.addTaskTableView reloadData];
    
    [AppUI initNavigationItem:self.navigationItem andWithText:@"确  认" andTextColor:WhiteColor andIsRight:YES withBlock:^{

        [self EditTaskToService];

    }];
}

-(void)EditTaskToService
{
    [API EditTaskWithTaskID:self.model.taskID projectID:((_isChangeProject==NO)?self.model.project_id:self.projectID) title:self.nameTF.text target_types:((_isChangeSort==NO)?self.model.target_types:self.sortIDsArr) priority:((_isChangePriority==NO)?self.model.priority:self.priorityID) estimate_stime:((_isChangeTime==NO)?self.model.estimate_stime:self.startTimeStr) target_desc:self.taskGoalTV.text exec_method:self.taskMethodTV.text memo:@"" attachments:self.dicKey success:^(id res)
    {
        NSLog(@"sdhfdh--%@",res[@"error"]);

        if ([res[@"rt"] isEqual:@(1)])
        {
            [self.view makeToast:@"修改成功" duration:1 position:CSToastPositionCenter];

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                    // 返回到任务列表界面
                    for (UIViewController *vc in self.navigationController.viewControllers)
                    {
                        if ([vc isKindOfClass:[TaskListViewController class]])
                        {
                            [self.navigationController popToViewController:vc animated:NO];
                        }
                    }
            });
        }
        else
        {
            [self.view makeToast:res[@"error"] duration:1 position:CSToastPositionCenter];
        }
        
    } failure:^(NSInteger stateCode) {

    }];
}

-(UIView *)taskInfoView
{
    if (!_taskInfoView) {
        _taskInfoView=[[UIView alloc]initWithFrame:CGRectMake(0,0,APPW,0)];
        _taskInfoView.backgroundColor=WhiteColor;
        setViewHeight_Add(_taskInfoView,kmargin);

        // 任务名称
        UILabel *taskNameLabel=[self.taskInfoView getLabelWithText:@"任务名称" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.taskInfoView addSubview:taskNameLabel];
        taskNameLabel.frame=CGRectMake(kmargin*2,_taskInfoView.frame.size.height,APPW/2,30);
        setViewHeight_Add(_taskInfoView,kmargin*3);

        _nameTF=[[UITextField alloc]initWithFrame:CGRectMake(kmargin*2,_taskInfoView.frame.size.height,APPW-kmargin*4,30)];
        _nameTF.text=self.model.title;
        _nameTF.delegate=self;
        _nameTF.textColor=DarkGreyColor;
//        _nameTF.borderStyle=UITextBorderStyleRoundedRect;
        [self.taskInfoView addSubview:_nameTF];
        _nameTF.font=Font_Number(16);
        setViewHeight_Add(_taskInfoView,kmargin*5);


        UIView *lineView1=[[UIView alloc]initWithFrame:CGRectMake(0,self.taskInfoView.frame.size.height,APPW,1)];
        lineView1.backgroundColor=MAIN_BACK_COLOR;
        [self.taskInfoView addSubview:lineView1];


        // 任务目标
        UILabel *taskGoalLabel=[self.taskInfoView getLabelWithText:@"任务目标" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.taskInfoView addSubview:taskGoalLabel];
        taskGoalLabel.frame=CGRectMake(kmargin*2,_taskInfoView.frame.size.height+kmargin,APPW/2,30);
        setViewHeight_Add(_taskInfoView,kmargin*4);

        _taskGoalTV=[[UITextView alloc]initWithFrame:CGRectMake(kmargin*3/2,_taskInfoView.frame.size.height,APPW-kmargin*3,kmargin*6)];
        _taskGoalTV.delegate=self;
        _taskGoalTV.text=self.model.target_desc;
        _taskGoalTV.textColor=DarkGreyColor;
        _taskGoalTV.font=Font_Number(16);
//        ViewBorderRadius(_taskGoalTV,2,1,MAIN_BACK_COLOR);
        [self.taskInfoView addSubview:_taskGoalTV];
        setViewHeight_Add(_taskInfoView,kmargin*8);

        UIView *lineView2=[[UIView alloc]initWithFrame:CGRectMake(0,_taskInfoView.frame.size.height,APPW,1)];
        lineView2.backgroundColor=MAIN_BACK_COLOR;
        [self.taskInfoView addSubview:lineView2];


        // 执行办法
        UILabel *taskMethodLabel=[self.taskInfoView getLabelWithText:@"执行办法" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.taskInfoView addSubview:taskMethodLabel];
        taskMethodLabel.frame=CGRectMake(kmargin*2,_taskInfoView.frame.size.height+kmargin,APPW/2,30);
        setViewHeight_Add(_taskInfoView,kmargin*4);

        _taskMethodTV=[[UITextView alloc]initWithFrame:CGRectMake(kmargin*3/2,_taskInfoView.frame.size.height,APPW-kmargin*3,kmargin*6)];
        _taskMethodTV.delegate=self;
        _taskMethodTV.text=self.model.exec_method;
        _taskMethodTV.textColor=DarkGreyColor;
        _taskMethodTV.font=Font_Number(16);
//        ViewBorderRadius(_taskMethodTV,2,1,MAIN_BACK_COLOR);
        [self.taskInfoView addSubview:_taskMethodTV];
        setViewHeight_Add(_taskInfoView,kmargin*8);

        UIButton *fileBtn=[AppUI createButtonWithSupeView:self.taskInfoView andWithNormalImage:[UIImage imageNamed:@"addFile"] andWithSelectImage:[UIImage imageNamed:@"addFile"] andWithBtnAction:^{

            // 跳转到 附件列表 界面
//            FileViewController *vc=[FileViewController new];
//            vc.fileArr=self.model.attachments;
//            [self.navigationController pushViewController:vc animated:NO];

            [self showSheetView];

        }];
        ViewBorderRadius(fileBtn,kmargin/2,.5,LightGreyColor);
        [self.taskInfoView addSubview:fileBtn];
        fileBtn.frame=CGRectMake(kmargin*2,_taskInfoView.frame.size.height,kmargin*4,kmargin*3);
        setViewHeight_Add(_taskInfoView,kmargin*5);

        UIView *lineView=[[UIView alloc]initWithFrame:CGRectMake(0,_taskInfoView.frame.size.height,APPW,kmargin)];
        lineView.backgroundColor=BGColor;
        [self.taskInfoView addSubview:lineView];
        setViewHeight_Add(_taskInfoView,kmargin);
    }
    return _taskInfoView;
}


// addTaskTableView
-(UITableView *)addTaskTableView
{
    if (!_addTaskTableView) {
        _addTaskTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,0,APPW,APPH) style:UITableViewStylePlain];
        _addTaskTableView.dataSource=self;
        _addTaskTableView.delegate=self;
        _addTaskTableView.backgroundColor=MAIN_BACK_COLOR;
        _addTaskTableView.showsVerticalScrollIndicator=NO;
        _addTaskTableView.tableHeaderView=self.taskInfoView;
        _addTaskTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
        self.addTaskTableView.tableFooterView=[UIView new];

        [self.addTaskTableView registerClass:[CommonTableViewCell class] forCellReuseIdentifier:CommonTableViewCellIdentifier];
        [self.addTaskTableView registerClass:[MemberTableViewCell class] forCellReuseIdentifier:MemberTableViewCellIdentifier];
        [self.addTaskTableView registerClass:[RemarkTableViewCell class] forCellReuseIdentifier:RemarkTableViewCellIdentifier];
    }
    return _addTaskTableView;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 所属项目
    if (indexPath.row==0)
    {
        CommonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CommonTableViewCellIdentifier];
        NSString *projectName;
        if (_isChangeProject==NO)
        {
            projectName=self.model.project_name;
        }
        else
        {
            projectName=self.projectName;
        }

        [cell setCellInfoWithHeaderImage:@"" withTitle:@"所属项目" withSubTitle:projectName withArrow:YES];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    // 任务分类
    else  if (indexPath.row==1)
    {
        CommonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CommonTableViewCellIdentifier];
        NSString *sortName;
        if (_isChangeSort==NO)
        {
            if (self.model.target_types.count==0)
            {
               sortName=@"请选择任务分类";
            }
            else
            {
             sortName=self.model.target_type_shows[self.model.target_types[0]];
            }
        }
        else
        {
            sortName=self.sortName;
        }

        [cell setCellInfoWithHeaderImage:@"" withTitle:@"任务分类" withSubTitle:sortName withArrow:YES];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    // 开始时间
    else  if (indexPath.row==2)
    {
        CommonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CommonTableViewCellIdentifier];
        NSString *timeStr;
        if (_isChangeTime==NO)
        {
            timeStr=self.model.estimate_stime;
        }
        else
        {
            timeStr=self.startTimeStr;
        }
        [cell setCellInfoWithHeaderImage:@"" withTitle:@"开始时间" withSubTitle:timeStr withArrow:YES];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    // 任务流程
    else  if (indexPath.row==3)
    {
        CommonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CommonTableViewCellIdentifier];
        [cell setCellInfoWithHeaderImage:@"" withTitle:@"任务流程" withSubTitle:@"" withArrow:NO];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    // 优先级
    else  if (indexPath.row==4)
    {
        CommonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CommonTableViewCellIdentifier];
        NSString *priorityStr;
        if (_isChangePriority==NO)
        {
            priorityStr=self.model.priority_show;
        }
        else
        {
            priorityStr=self.priorityStr;
        }

        [cell setCellInfoWithHeaderImage:@"" withTitle:@"优  先  级" withSubTitle:priorityStr withArrow:YES];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        RemarkTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:RemarkTableViewCellIdentifier];
        cell.delegate=self;
        cell.remarkTextView.text=self.model.memo;
        cell.remarkTextView.textColor=LightGreyColor;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    if (indexPath.row==0)
    {
        // 跳转到 项目列表 界面
        ProjectListViewController *vc=[ProjectListViewController new];
        vc.delegate=self;
        [self.navigationController pushViewController:vc animated:NO];
    }
    else if (indexPath.row==1)
    {
        // 跳转到 分类列表 界面
        TaskSortViewController *vc=[TaskSortViewController new];
        vc.delegate=self;
        [self.navigationController pushViewController:vc animated:NO];
    }
    else if (indexPath.row==2)
    {
        // 开始时间
        [self GetStartTime];
    }
    else if (indexPath.row==3)
    {
        // 跳转到 任务流程 界面
        TaskProcessViewController *vc=[TaskProcessViewController new];
        vc.taskID=self.model.taskID;
        [self.navigationController pushViewController:vc animated:NO];
    }
    else if (indexPath.row==4)
    {
        // 获取优先级数据
        [self GetPriorityListData];
    }
}

// delegate
-(void)selectProjectName:(NSString *)projectName projectID:(NSString *)projectID
{
    _isChangeProject=YES;
    self.projectName=projectName;
    self.projectID=projectID;
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
   [_addTaskTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}

// delegate
-(void)selectTaskSortName:(NSString *)taskSortName taskSortID:(NSString *)taskSortID
{
    _isChangeSort=YES;
    self.sortName=taskSortName;
    [self.sortIDsArr addObject:taskSortID];
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];
 [_addTaskTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}

// 开始时间
-(void)GetStartTime
{
    CuiPickerView *pickerView=[CuiPickerView new];
    pickerView.frame=CGRectMake(0,APPH,APPW,320);
    pickerView.delegate=self;
    pickerView.backgroundColor=BGColor;
    pickerView.curDate=[NSDate date];
    _pickerView=pickerView;
    [self.view addSubview:pickerView];
    [_pickerView showInView:self.view];
}

// delegate
-(void)didFinishPickView:(NSString *)date
{
    _isChangeTime=YES;

    self.startTimeStr=date;
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:2 inSection:0];
    [_addTaskTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}

-(void)hiddenPickerView
{

}


// 获取优先级数据
-(void)GetPriorityListData
{
    [API GetPriorityListSuccess:^(id res) {
        NSDictionary *dic=res[@"rows"];
        LQPopUpView *popUpView = [[LQPopUpView alloc] initWithTitle:@"选择优先级" message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[dic[@"1"],dic[@"3"]] actionWithIndex:^(NSInteger index) {

            _isChangePriority=YES;
            // 普通
            if (index==1)
            {
                self.priorityStr=@"普通";

                self.priorityID=@"1";
            }
//            // 高
//            else if (index==2)
//            {
//                self.priorityStr=@"高";
//                self.priorityID=@"2";
//            }
            // 紧急
            else if (index==2)
            {
                self.priorityStr=@"紧急";
                self.priorityID=@"3";
            }
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:4 inSection:0];
            [self.addTaskTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        }];

        [popUpView showInView:self.view preferredStyle:LQPopUpViewStyleAlert];

    } failure:^(NSInteger stateCode) {

    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kmargin*5;
}

// 间隙置边
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}


-(void)showSheetView
{
    UIAlertController *alert=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *setAlert=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self callCameraOrPhotoWithType:UIImagePickerControllerSourceTypeCamera];

    }];
    UIAlertAction *PhoneAlert=[UIAlertAction actionWithTitle:@"从手机选择" style:
                               UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                   TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:2 delegate:self];

                                   // 在这里设置imagePickerVc的外观
                                   imagePickerVc.navigationBar.barTintColor=MainColor;
                                   imagePickerVc.oKButtonTitleColorDisabled=MainColor;
                                   imagePickerVc.oKButtonTitleColorNormal=[UIColor greenColor];
                                   // 设置是否可以选择视频/原图
                                   imagePickerVc.allowPickingVideo=YES;
                                   imagePickerVc.allowPickingOriginalPhoto=YES;
                                   imagePickerVc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
                                   [self presentViewController:imagePickerVc animated:NO completion:nil];

                               }];
    UIAlertAction *hidAlert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alert addAction:setAlert];
    [alert addAction:PhoneAlert];
    [alert addAction:hidAlert];

    [self presentViewController:alert animated:NO completion:^{

    }];
}

-(void)callCameraOrPhotoWithType:(UIImagePickerControllerSourceType)sourceType{
    BOOL isCamera = YES;
    if (sourceType == UIImagePickerControllerSourceTypeCamera) {//判断是否有相机
        isCamera = [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera];
    }
    if (isCamera) {
        UIImagePickerController *imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.delegate=self;
        imagePicker.allowsEditing=NO;//为NO，则不会出现系统的编辑界面
        imagePicker.sourceType = sourceType;
        [self presentViewController:imagePicker animated:YES completion:^(){
            if ([[[UIDevice currentDevice] systemVersion]floatValue]>=7.0) {
                [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
            }
        }];
    }
    else
    {
        UIAlertView *alert=[UIAlertView alertViewWithTitle:@"该设备不支持拍照" message:nil cancelButtonTitle:nil didDismissBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
        } otherButtonTitles:@"确定", nil];
        [alert show];
    }
}

#pragma mark - TZImagePickerController Delegate
// 处理从相册单选或多选的照片
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto
{

    NSLog(@"hdsshd00---%@",photos);
    //图片压缩
    UIImage *uploadImage=photos[0];

    uploadImage=[Util scaleToSize:uploadImage size:CGSizeMake(180,uploadImage.size.height*(180.0/MAX(uploadImage.size.width,180)))];
    // 图片转向处理
    uploadImage =[uploadImage fixOrientation];

    // 获取当前时间
    NSDate *date=[NSDate date];
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMddHHmmssss"];

    NSData *imageData=UIImageJPEGRepresentation(uploadImage,0.9f);
    NSString *uniquePath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",[formatter stringFromDate:date]]];
    [imageData writeToFile:uniquePath atomically:NO];
    NSLog(@"sh99999999---%@",uniquePath);
    NSData *data=[NSData dataWithContentsOfFile:uniquePath];
    //        NSLog(@"77777---%@",data);

    NSString *key=[NSURL fileURLWithPath:uniquePath].lastPathComponent;
    NSLog(@"sfhfdh66---%@",key);




    MCAWSS3Client *client=[MCAWSS3Client new];
    [client setAccessKey:[Util getUserDefaultObjectForKey:@"access_key"]];
    [client setSecretKey:[Util getUserDefaultObjectForKey:@"access_secret"]];
    [client setSessionToken:[Util getUserDefaultObjectForKey:@"TToken"]];
    [client setBucket:[Util getUserDefaultObjectForKey:@"bucket"]];


    NSString *filePathUrl=[NSString stringWithFormat:@"%@%@",FilePathBaseUrl,key];
    NSLog(@"SDHJSDHHHDF0---%@",filePathUrl);

    NSDictionary *dic=@{
                        @"name":key,
                        @"url":filePathUrl,
                        @"type":@"png",
                        @"size":[NSString stringWithFormat:@"%llu",uniquePath.fileSize]
                        };

    NSLog(@"sfhfdff----%@",[Util transformedValue:@(uniquePath.fileSize)]);

    NSLog(@"sdhjdhfhfd0---%@",dic);

    [client putObjectWithData:data
                          key:key
                     mimeType:@"image/png"
                   permission:MCAWSS3ObjectPermissionPublicReadWrite
                      success:^(AFHTTPRequestOperation *operation,id responseObject) {

                          NSLog(@"sdhjshdsj7770---%@  000---%@",operation,responseObject);
                          [self.view makeToast:@"附件上传成功" duration:1 position:CSToastPositionCenter];


                          _isChangeFile=YES;

                          //    [self.parameters setObject:goodsIDArr forKey:@"serviceIds"];

                          [self.dicKey setObject:dic forKey:key];
                          
//                          [self.fileArr addObject:dic];

                          NSLog(@"sdhshd2222----%@",self.dicKey);
                          
                          
                          //                          [self.fileArr addObject:self.dicKey];
                          
                          //                          [self.fileArr addObject:goodsIDArr];
                          
//                          NSLog(@"sdhjds999---%@",self.fileArr);

                          
                      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                          
                      }];
}



// 点击return键时候键盘下去
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];

    return YES;
}


@end
